import React from 'react';
import * as Sys from '../sys';

interface IPageFooter {
    currentTimestamp: Date,
}

class PageFooter extends React.Component<{}, IPageFooter> {
    constructor(props: {}) {
        super(props);

        this.state = {
            currentTimestamp: null,
        };
    }

    componentDidMount = () => {
        const refreshTimestamp = () => this.setState({ currentTimestamp: new Date() });
        refreshTimestamp();
        setInterval(refreshTimestamp, 5000);
    };

    shouldComponentUpdate = (nextProps: {}, nextState: IPageFooter) => nextState.currentTimestamp !== this.state.currentTimestamp;

    render = (): JSX.Element => {
        return <footer className="ui secondary segment">
            <div className="ui center aligned container">
                <p>An sample website for armory backend and frontend</p>
                <p><span>此页面生成于：</span><span>{this.state && Sys.formatFromNow(this.state.currentTimestamp)}</span></p>
            </div>
        </footer>;
    };
}

export { PageFooter };